<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>聘途</title>
    <link rel="icon" href="/image/favicon.ico" type="image/x-icon"/>
    <script src="/vue.min.js"></script>
    <script src="/axios.min.js"></script>
    <style>
        .home-page {
            border: none;
            height: 1200px;
            background-image: linear-gradient(to bottom, #d1eded, white);
            background-position: to center;

        }

        .menu {
            border: none;
            height: 5%;
            background-color: #202329;
            display: flex;
            align-items: center;
            /*垂直居中*/
        }

        .menu1 {
            list-style-type: none;
            margin-left: 5%;
            overflow: hidden;
        }

        .menu2 {
            text-align: center;
            color: white;
            float: left;
            width: 140px;
            font-size: large;


        }

        .menu2:hover {
            color: #00b4b3;
        }

        .usercenter {
            list-style-type: none;
            overflow: hidden;
            float: left;
            color: rgb(255, 255, 255);
            font-size: large;
            display: flex;
            margin-left: 800px;

        }

        .usercenter:hover {
            color: #00b4b3;
        }


        .image {
            margin-top: 5%;
            border: none;
            height: 11%;
            background-image: url('/image/求职者首页图片1.jpeg');
            background-size: 100% 100%;
        }


        .search1 {
            width: 600px;
            height: 45px;
            background-color: white;
            margin-top: 4%;
            margin-left: 32%;
            border-radius: 15px;

        }

        #searchselect {
            border: none;
            outline: none;
            width: 100px;
            height: 40px;
            border-radius: 15px;


        }

        .search1 input {
            margin-left: 0px;
            border: none;
            outline: none;
            width: 410px;
            height: 40px;
            border-radius: 15px;
            font-size: large;
        }

        #bt {
            background-color: white;
            width: 70px;
            border: none;
            outline: none;
            cursor: pointer;
            /* 将鼠标样式改为指针样式 */
            transition: all 0.3s ease;
            /* 添加过渡效果 */
        }

        #bt:hover {
            background-color: #aababa;
        }

        .pagination {
            margin-top: 8%;
            text-align: center;
        }

        .page {
            border-radius: 16px;
            width: 150px;
            height: 40px;
            border: rgb(235, 228, 228) solid 1px;
            background-color: white;
            font-size: large;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .page:hover {
            color: #aababa;
        }

        .work {
            margin-top: 5%;
            margin-left: 5%;
            display: flex;
            gap: 120px
        }

        .company {
            display: flex;

            margin-top: 100px;
            width: 460px;
            height: 270px;
            background-color: #fdf8f8;
            color: rgb(0, 0, 0);
            border: 1px;
            cursor: pointer;
            transition: all 0.3s ease;
            border-radius: 15px;
        }

        .company:hover {
            color: rgb(122, 226, 205)
        }

        .p1 {
            position: absolute;
            margin: 0;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="home-page">
            <div class="menu">
                <h2 style="margin-left: 10%;color: #2fdfd1;">聘途</h2>
                <ul class="menu1">
                    <a href="首页.html">
                        <li class="menu2">首页</li>
                    </a>
                    <a href="推荐.html">
                        <li class="menu2">推荐</li>
                    </a>
                    <a href="首页公司.html">
                        <li class="menu2">公司</li>
                    </a>
                    <a href="APP.html">
                        <li class="menu2">APP</li>
                    </a>

                </ul>

                <a href="修改密码.html">
                    <li class="usercenter"> {{ userInfo.sname }}</li>
                </a>

            </div>

            <div class="search">
                <form @submit.prevent="submitForm">
                    <div class="search1">
                        <select id="searchselect" v-model="searchselect">
                            <option value="岗位">按岗位搜索</option>

                            <option value="公司">按公司搜索</option>
                        </select>

                        <input type="text" v-model="searchinput" placeholder="请输入搜索内容">
                        <input type="submit" value="搜索" id="bt">
                    </div>
                </form>




            </div>

            <div class="image"> </div>

            <div class="work">

                <div v-for="(CompanyInfo, index) in companyInfoPage1" :key="index">



                    <button class="company" @click="companydescribe(CompanyInfo)">
                        <p class="p1" style="margin-left: 100px;margin-top: 80px ;font-family: 宋体;font-size: 26px;">
                            <b>{{CompanyInfo.cname}}</b>
                        </p>
                        <p class="p1"
                            style="margin-left: 230px;margin-top: 85px ;font-family: 宋体;font-size: 20px;color: rgba(0, 204, 255, 0.702) ;">
                            <b>[{{CompanyInfo.caddress}}]</b>
                        </p>
                        <p class="p1"
                            style="margin-left: 130px;margin-top: 130px ;font-family: 宋体;font-size: 23px;color: rgba(0, 0, 0, 0.702) ;">
                            创立于{{CompanyInfo.cyear}}年
                        </p>
                        <p class="p1"
                            style="margin-left: 260px;margin-top: 240px ;font-family: 宋体;font-size: 16px;color: rgba(0, 0, 0, 0.702) ;">
                            联系方式：{{CompanyInfo.cphone}}
                        </p>

                    </button>


                </div>


            </div>

            <div class="pagination">
                <button class="page" @click="prevPage" :disabled="currentPage === 1">上一页</button>
                <button class="page" @click="nextPage"
                    :disabled="currentPage === companyInfo.length / 3">下一页</button>
            </div>



        </div>
    </div>

    <script>
        var userInfo = JSON.parse(sessionStorage.getItem('userData'));
        var companyInfo = JSON.parse(sessionStorage.getItem('companyinfo'));

        new Vue({
            el: '#app',
            data: {
                searchselect: '岗位',
                searchinput: '',
                currentPage: '1',
                companyInfoPage1: '',
                comepanyInfoPage2: ''

            },

            created() {
                // 假设workInfo是已经从服务器获取到的所有岗位数据的数组
                this.companyInfo = companyInfo; // 确保这是响应式的

                // 初始化时显示第一页的数据
                this.currentPage = 1;
                this.companyInfoPage1 = this.companyInfo.slice(0, 3); // 显示前三个岗位
            },

            methods: {

                companydescribe(CompanyInfo) {
                    console.log(CompanyInfo);
                    sessionStorage.setItem('CompanyInfo', JSON.stringify(CompanyInfo));
                    window.location.href = "点进公司.html";

                },

                
                nextPage() {
                        if (this.currentPage < Math.ceil(this.companyInfo.length / 3)) {
                            this.currentPage += 1;
                            this.companyInfoPage1 = this.companyInfo.slice(this.currentPage * 3 - 3, this.currentPage * 3);
                        }
                    },
                    prevPage() {
                        if (this.currentPage > 1) {
                            this.currentPage -= 1;
                            this.companyInfoPage1 = this.companyInfo.slice(this.currentPage * 3 - 3, this.currentPage * 3);
                        }
                    },


                submitForm() {


                    let data = new FormData();
                    data.append("choice", this.searchselect);
                    data.append("keyword", this.searchinput);


                    axios.post("http://localhost:8080/hqdx/seeker/searchforPosition", data)
                        .then(response => {
                            if (response.data.success == true) {
                                if (response.data.data.choice2 == '岗位') {

                                    window.location.href = "岗位分类.html";
                                    sessionStorage.setItem('workinfo', JSON.stringify(response.data.data.items));

                                }

                                else {
                                    console.log(response.data.data.items)
                                    window.location.href = "公司.html";
                                    sessionStorage.setItem('companyinfo', JSON.stringify(response.data.data.items));

                                }


                            }
                            else {
                                alert('无法找到搜索内容')
                            }
                        })
                        .catch(error => {
                            console.log(error);
                        });
                },


            }
        })
    </script>
</body>

</html>